package com.leps.nq.op.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leps.nq.bi.vo.SimpleEntry;
import com.leps.nq.common.vo.PageVo;
import com.leps.nq.op.entity.OpWaterTest;
import com.leps.nq.op.mapper.OpWaterTestMapper;
import com.leps.nq.op.service.IOpWaterTestService;
import com.leps.nq.op.vo.WaterTestQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 水样检测记录表 服务实现类
 * </p>
 *
 * @author hex
 * @since 2022-05-22
 */
@Service
public class OpWaterTestServiceImpl extends ServiceImpl<OpWaterTestMapper, OpWaterTest> implements IOpWaterTestService {
    @Autowired
    OpWaterTestMapper waterTestMapper;

    @Override
    public PageVo<OpWaterTest> pageByQueryModel(WaterTestQueryModel queryModel) {
        Page<OpWaterTest> page = Page.of(queryModel.getPageNum(), queryModel.getPageSize());
        page = this.waterTestMapper.selectByQueryModel(page, queryModel);
        return PageVo.of(page);
    }

    @Override
    public List<SimpleEntry<Double>> getRecentIrons(int pumpId) {
        List<SimpleEntry<Double>> list = this.waterTestMapper.selectRecentIrons(pumpId);
        if (list != null)
            Collections.reverse(list);
        return list;
    }

    @Override
    public List<SimpleEntry<Double>> getRecentColonys(int pumpId) {
        List<SimpleEntry<Double>> list = this.waterTestMapper.selectRecentColonys(pumpId);
        if (list != null)
            Collections.reverse(list);
        return list;
    }
}
